package com.zyc.webtest.controller;

import com.zyc.webtest.utils.ResultMsg;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
@RequestMapping("manage")
public class ManageController extends BaseController {


    @GetMapping(value = {"", "/"})
    public String index() {
        return "manage/index" ;
    }

    @GetMapping(value = {"/home"})

    public String index2() {
        return "manage/main" ;
    }

    @PostMapping(value = {"/login"})
    public ResultMsg login(@RequestParam(value="userName") String userName,@RequestParam(value="password") String password) {
        UsernamePasswordToken upt = new UsernamePasswordToken(userName,password);
        Subject currentUser = SecurityUtils.getSubject();
        currentUser.login(upt);
        if(currentUser.isAuthenticated()){
            return ResultMsg.success();
        }
        return ResultMsg.error();
    }
}
